import logging
import os
import time
class LogUtil:
    def __init__(self):
        self.logger=logging.getLogger('loging')
        self.logger.setLevel(logging.DEBUG)
        if not self.logger.handlers:
            self.log_name=f'{time.strftime("%Y_%m_%d",time.localtime())}.log'
            path=os.path.dirname(os.path.dirname(__file__))+'\log'
            self.log_path=os.path.join(path,self.log_name)
            fh=logging.FileHandler(self.log_path,encoding='utf-8',mode='a')
            fh.setLevel(logging.DEBUG)
            matter=logging.Formatter('%(asctime)s-%(filename)s[line:%(lineno)d]-%(levelname)s:%(message)s')
            fh.setFormatter(matter)
            self.logger.addHandler(fh)
            fh.close()
            fh_stream=logging.StreamHandler()
            fh_stream.setFormatter(matter)
            fh_stream.setLevel(logging.DEBUG)
            self.logger.addHandler(fh_stream)
    def log(self):
        return self.logger
logger=LogUtil().log()
